package com.example.project.projectspringcloud.entity.user;

import com.example.project.projectspringcloud.entity.BaseEntity;
import com.example.project.projectspringcloud.utils.StringUtil;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.apache.commons.lang3.StringUtils;

import java.math.BigDecimal;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;

@Data
@EqualsAndHashCode(callSuper = false)
public class Evaluate extends BaseEntity {

    /**
     * 用户id
     */
    private Integer userId;

    /**
     * 匿名
     */
    private Integer anonymous;

    /**
     * 评价目标
     */
    private Integer target;

    /**
     * 评价目标类型
     */
    private Integer targetType;

    /**
     * 标签
     */
    private String tags;

    /**
     * 分数
     */
    private BigDecimal score;

    /**
     * 评价内容
     */
    private String comment;

    /**
     * 回复
     */
    private String reply;

    /**
     * 评价类型
     */
    private Integer type;

    /**
     * 业务用附加字段 ////
     * 评论用户
     */
    private User evaluateUser;

    /**
     * 筛选类型列表
     */
    private Integer[] targetTypes;

    public Evaluate() {

    }

    public Evaluate(Integer target, Integer targetType) {
        this.target = target;
        this.targetType = targetType;
    }

    public Integer[] getTagsArray() {
        if (StringUtils.isNotBlank(tags)) {
            return StringUtil.split(tags, ",");
        }
        return null;
    }

    public Set<Integer> getTagsSet() {
        if (StringUtils.isNotBlank(tags)) {
            Integer[] arr = StringUtil.split(tags, ",");
            return new HashSet<>(Arrays.asList(arr));
        }
        return null;
    }
}